// 倒计时功能
let countdownTime = 29 * 60 + 49; // 29分49秒转换为秒
const countdownElement = document.querySelector('.countdown strong');

function updateCountdown() {
    const minutes = Math.floor(countdownTime / 60);
    const seconds = countdownTime % 60;
    countdownElement.textContent = `${minutes}分${seconds < 10 ? '0' : ''}${seconds}秒`;
    countdownTime--;

    if (countdownTime < 0) {
        clearInterval(countdownInterval);
        alert('订单已取消');
    }
}

const countdownInterval = setInterval(updateCountdown, 1000);

// 切换支付方式选项
const tabs = document.querySelectorAll('.tab');
tabs.forEach(tab => {
    tab.addEventListener('click', function() {
        tabs.forEach(t => t.classList.remove('active'));
        this.classList.add('active');
    });
});

// 确认支付按钮事件
document.querySelector('.pay-button').addEventListener('click', function() {
    alert('跳转到支付页面...');
});
document.addEventListener("DOMContentLoaded", function () {
    // 获取所有的 tab 按钮和支付方式 div
    const tabs = document.querySelectorAll(".tab");
    const paymentMethod1 = document.querySelector(".payment-method1");
    const paymentMethod2 = document.querySelector(".payment-method2");
    const paymentMethod3 = document.querySelector(".payment-method3");

    // 设置默认显示第一个支付方式
    paymentMethod1.style.display = "block";
    paymentMethod2.style.display = "none";
    paymentMethod3.style.display = "none";

    // 添加点击事件监听器
    tabs.forEach((tab, index) => {
        tab.addEventListener("click", function () {
            // 移除所有 tab 的 active 样式
            tabs.forEach(t => t.classList.remove("active"));
            // 当前 tab 添加 active 样式
            tab.classList.add("active");

            // 根据点击的 tab 显示相应的支付方式 div
            if (index === 0) { // 支付宝
                paymentMethod1.style.display = "block";
                paymentMethod2.style.display = "none";
                paymentMethod3.style.display = "none";
            } else if (index === 1) { // 微信
                paymentMethod1.style.display = "none";
                paymentMethod2.style.display = "block";
                paymentMethod3.style.display = "none";
            } else if (index === 2) { // 银行卡
                paymentMethod1.style.display = "none";
                paymentMethod2.style.display = "none";
                paymentMethod3.style.display = "block";
            }
        });
    });
});
